//
//  UIView+Frame.h
//  
//
//  Created by Tzzzzz on 16/3/7.
//  Copyright © 2016年 Windward. All rights reserved.
//

#import "UIView+Frame.h"

@implementation UIView (Frame)

- (CGFloat)centerX
{
    return self.center.x;
}

- (void)setCenterX:(CGFloat)centerX
{
    CGPoint center = self.center;
    center.x = centerX;
    self.center = center;
}

- (void)setCenterY:(CGFloat)centerY
{
    CGPoint center = self.center;
    center.y = centerY;
    self.center = center;
}

- (CGFloat)centerY
{
    return self.center.y;
}

- (CGFloat)x
{
    return self.frame.origin.x;
}

- (void)setX:(CGFloat)x
{
    CGRect frame = self.frame;
    frame.origin.x = x;
    self.frame = frame;
}

- (CGFloat)y
{
    return self.frame.origin.y;
}

- (void)setY:(CGFloat)y
{
    CGRect frame = self.frame;
    frame.origin.y = y;
    self.frame = frame;
}

- (CGFloat)width
{
    return self.frame.size.width;
}
- (void)setWidth:(CGFloat)width
{
    CGRect frame = self.frame;
    frame.size.width = width;
    self.frame = frame;

}

- (CGFloat)height
{
    return self.frame.size.height;
}

- (void)setHeight:(CGFloat)height
{
    CGRect frame = self.frame;
    frame.size.height = height;
    self.frame = frame;
}

- (CGSize)size
{
    return self.frame.size;
}

- (void)setSize:(CGSize)size
{
    CGRect frame = self.frame;
    frame.size = size;
    
    self.frame = frame;
}

- (CGPoint)origin
{
    return self.frame.origin;
}

- (void)setOrigin:(CGPoint)origin
{
    CGRect frame = self.frame;
    frame.origin = origin;
    
    self.frame = frame;
}


- (void)setMaxX:(CGFloat)maxX
{
    self.x = maxX - self.width;
}


- (CGFloat)maxX
{
    return CGRectGetMaxX(self.frame);
}

- (void)setMaxY:(CGFloat)maxY
{
    self.y = maxY - self.height;
}

- (CGFloat)maxY
{
    return CGRectGetMaxY(self.frame);
}



+ (instancetype)viewFromXib
{
    return [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:nil options:nil] lastObject];
}

- (void)setupViewCorners: (CGSize) size {
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:size];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = self.bounds;
    maskLayer.path = maskPath.CGPath;
    self.layer.mask = maskLayer;
}

+ (instancetype)createMarginView:(UIColor *)color {
    UIView *view = [UIView new];
    view.backgroundColor = color;
    view.frame = CGRectMake(0, 0, ScreenWidth, 10);
    return view;
}

+ (instancetype)noneCommentView {
    UIView *noneView = [UIView new];
    noneView.frame = CGRectMake(0, 0, ScreenWidth, 44);
    noneView.backgroundColor = [UIColor redColor];
    UILabel *tipLabel = [UILabel new];
    tipLabel.text = @"当前暂无评论~";
    tipLabel.font = [UIFont systemFontOfSize:15];
    tipLabel.textAlignment = NSTextAlignmentCenter;
    tipLabel.frame = CGRectMake(0, 15, ScreenWidth, 15);
    tipLabel.textColor = [UIColor colorWithHexString:@"d0d0d0"];
    [noneView addSubview:tipLabel];
    return noneView;
}

+ (instancetype)noneDataView {
    UIView *noneView = [UIView new];
    noneView.frame = CGRectMake(0, 0, ScreenWidth, ScreenHeight);
    noneView.backgroundColor = [UIColor redColor ];
    UILabel *tipLabel = [UILabel new];
    tipLabel.text = @"当前暂无数据~";
    tipLabel.font = [UIFont systemFontOfSize:15];
    tipLabel.textAlignment = NSTextAlignmentCenter;
    tipLabel.frame = CGRectMake(0, 0, ScreenWidth, 15);
    tipLabel.centerY = ScreenHeight * 0.4;
    tipLabel.textColor = [UIColor colorWithHexString:@"d0d0d0"];
    [noneView addSubview:tipLabel];
    return noneView;
}


@end
